package com.huobao.yunying.fragments;

import java.util.List;
import java.util.Map;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.huobao.yunying.adapters.Adapter_Save_Progect;
import com.huobao.yunying.entity.SaveProgect;
import com.huobao.yunying.https.Http;
import com.huobao.yunying.https.HttpListener;
import com.huobao.yunying.https.HttpUtil;
import com.huobao.yunying.utils.SkipUtils;
import com.huobao.zhangying.R;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListView;

public class Save_Progect extends BaseFragment implements OnItemClickListener {

	private ListView listview;
	private Adapter_Save_Progect adapter;

	@Override
	public View onCreateContentView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
		View view = inflater.inflate(R.layout.layout_save_fragment, null);
		listview = (ListView) view.findViewById(R.id.listview);
		adapter = new Adapter_Save_Progect(getActivity());
		listview.setAdapter(adapter);
		listview.setOnItemClickListener(this);
		get();
		return view;
	}

	@Override
	public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
		SkipUtils.seeDetail(getActivity(), adapter.getItem(position).goods_id, adapter.getItem(position).default_image);
	}

	private void get() {
		Map<String, String> map = HttpUtil.getParams("app", "member", "act", "goods_collect_list");
		Http.getInstant().sendRequest(getActivity(), map, new HttpListener() {

			@Override
			public void onHttpSuccess(String result) {
				JSONObject jsonObject = JSON.parseObject(result);
				List<SaveProgect> list = JSON.parseArray(jsonObject.getString("retval"), SaveProgect.class);
				adapter.addAll(list);
				showContentView();
			}

			@Override
			public void onHttpError(String error) {
				// TODO Auto-generated method stub

			}
		});
	}
}
